/* 

	In this file we setup our Windows, Columns and Panels,
	and then inititialize MochaUI.
	
	At the bottom of Core.js you can setup lazy loading for your
	own plugins.

*/

/*
  
INITIALIZE WINDOWS

	1. Define windows
	
		var myWindow = function(){ 
			new MUI.Window({
				id: 'mywindow',
				title: 'My Window',
				contentURL: 'pages/lipsum.html',
				width: 340,
				height: 150
			});
		}

	2. Build windows on onDomReady
	
		myWindow();
	
	3. Add link events to build future windows
	
		if ($('myWindowLink')){
			$('myWindowLink').addEvent('click', function(e) {
				new Event(e).stop();
				jsonWindows();
			});
		}

		Note: If your link is in the top menu, it opens only a single window, and you would
		like a check mark next to it when it's window is open, format the link name as follows:

		window.id + LinkCheck, e.g., mywindowLinkCheck

		Otherwise it is suggested you just use mywindowLink

	Associated HTML for link event above:

		<a id="myWindowLink" href="pages/lipsum.html">My Window</a>	


	Notes:
		If you need to add link events to links within windows you are creating, do
		it in the onContentLoaded function of the new window. 
 
-------------------------------------------------------------------- */

var oTimer = null;

initializeWindows = function(){

	// Examples
	
	MUI.htmlWindow = function(){
		new MUI.Window({
			id: 'htmlpage',
			content: 'Hello World',
			width: 340,
			height: 150
		});
	}	
	
	MUI.ajaxpageWindow = function(){
		new MUI.Window({
			id: 'ajaxpage',
			contentURL: 'pages/lipsum.html',
			width: 340,
			height: 150
		});
	}	
	if ($('ajaxpageLinkCheck')){ 
		$('ajaxpageLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MUI.ajaxpageWindow();
		});
	}	
	
	MUI.jsonWindows = function(){
		var request = new Request.JSON({
			url: 'data/json-windows-data.js',
			onComplete: function(properties) {
				MUI.newWindowsFromJSON(properties.windows);
			}
		}).send();
	}	
	if ($('jsonLink')){
		$('jsonLink').addEvent('click', function(e) {
			new Event(e).stop();
			MUI.jsonWindows();
		});
	}

	MUI.youtubeWindow = function(){
		new MUI.Window({
			id: 'youtube',
			title: 'YouTube in Iframe',
			loadMethod: 'iframe',
			contentURL: 'pages/youtube.html',
			width: 340,
			height: 280,
			resizeLimit: {'x': [330, 2500], 'y': [250, 2000]},
			toolbar: true,
			toolbarURL: 'pages/youtube-tabs.html',
			toolbarOnload: function(){
				MUI.initializeTabs('youtubeTabs');	

				$('youtube1Link').addEvent('click', function(e){
					MUI.updateContent({
						'element':  $('youtube'),
						'url':      'pages/youtube.html'
					});
				});
	
				$('youtube2Link').addEvent('click', function(e){
					MUI.updateContent({
						'element':  $('youtube'),
						'url':      'pages/youtube2.html'
					});
				});
	
				$('youtube3Link').addEvent('click', function(e){
					MUI.updateContent({
						'element':  $('youtube'),	
						'url':      'pages/youtube3.html'
					});
				});	
			}
		});
	}
	if ($('youtubeLinkCheck')) {
		$('youtubeLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MUI.youtubeWindow();
		});
	}
	
	MUI.clockWindow = function(){
		new MUI.Window({
			id: 'clock',
			title: 'Canvas Clock',
			addClass: 'transparent',
			contentURL: MUI.path.plugins + 'coolclock/index.html',
			shape: 'gauge',
			headerHeight: 30,
			width: 160,
			height: 160,
			x: 570,
			y: 140,
			padding: { top: 0, right: 0, bottom: 0, left: 0 },
			require: {			
				js: [MUI.path.plugins + 'coolclock/scripts/coolclock.js'],
				onload: function(){
					if (CoolClock) new CoolClock();
				}	
			}				
		});	
	}
	if ($('clockLinkCheck')){
		$('clockLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MUI.clockWindow();
		});
	}	
	
	MUI.parametricsWindow = function(){	
		new MUI.Window({
			id: 'parametrics',
			title: 'Window Parametrics',			
			contentURL: MUI.path.plugins + 'parametrics/index.html',
			width: 305,
			height: 110,
			x: 570,
			y: 160,
			padding: { top: 12, right: 12, bottom: 10, left: 12 },
			resizable: false,
			maximizable: false,
			require: {
				css: [MUI.path.plugins + 'parametrics/css/style.css'],
				js: [MUI.path.plugins + 'parametrics/scripts/parametrics.js'],
				onload: function(){	
					if (MUI.addRadiusSlider) MUI.addRadiusSlider();
					if (MUI.addShadowSlider) MUI.addShadowSlider();
				}		
			}				
		});
	}
	if ($('parametricsLinkCheck')){
		$('parametricsLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MUI.parametricsWindow();
		});
	}
	
	MUI.splitWindow = function(){
		new MUI.Window({
			id: 'splitWindow',
			title: 'Split Window',
			width: 600,
			height: 350,
			resizeLimit: {'x': [450, 2500], 'y': [300, 2000]},
			scrollbars: false, // Could make this automatic if a 'panel' method were created
			onContentLoaded: function(){	
		
				new MUI.Column({
					container: 'splitWindow_contentWrapper',
					id: 'splitWindow_sideColumn',
					placement: 'left',
					width: 170,
					resizeLimit: [100, 300]
				});
			
				new MUI.Column({
					container: 'splitWindow_contentWrapper',
					id: 'splitWindow_mainColumn',
					placement: 'main',
					width: null,
					resizeLimit: [100, 300]
				});
			
				new MUI.Panel({
					header: false,
					id: 'splitWindow_panel1',					
					contentURL: 'license.html',
					column: 'splitWindow_mainColumn',
					panelBackground: '#fff'
				});
			
				new MUI.Panel({
					header: false,
					id: 'splitWindow_panel2',
					addClass: 'panelAlt',					
					contentURL: 'pages/lipsum.html',
					column: 'splitWindow_sideColumn'					
				});

			}			
		});
	}
	if ($('splitWindowLinkCheck')) {
		$('splitWindowLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MUI.splitWindow();
		});
	}
	
	MUI.fxmorpherWindow = function(){
		new MUI.Window({
			id: 'fxmorpherExample',
			title: 'Path Animation Example',			
			contentURL: MUI.path.plugins + 'Fx.Morpher/example.html',
			width: 330,
			height: 330,
			padding: { top: 0, right: 0, bottom: 0, left: 0 },
			scrollbars: false,
			resizable: false,
			require: {
				css: [MUI.path.plugins + 'Fx.Morpher/css/style.css'],
				js: [MUI.path.plugins + 'Fx.Morpher/scripts/cbox.js', MUI.path.plugins + 'Fx.Morpher/scripts/example.js'],
				onload: function(){
					createCanvas();
					myAnim.delay(250);					
				} 	
			}			
		});	
	}			

	// Examples > Tests
	
	MUI.serverRepsonseWindow = function(response){
		new MUI.Window({
			id: 'serverResponse',
			content: response,
			width: 350,
			height: 350
		});
	}		
	
	MUI.eventsWindow = function(){
		new MUI.Window({
			id: 'windowevents',
			title: 'Window Events',			
			contentURL: 'pages/events.html',
			width: 340,
			height: 250,			
			onContentLoaded: function(windowEl){
				MUI.notification('Window content was loaded.');
			},
			onCloseComplete: function(){
				MUI.notification('The window is closed.');
			},
			onMinimize: function(windowEl){
				MUI.notification('Window was minimized.');
			},
			onMaximize: function(windowEl){
				MUI.notification('Window was maximized.');
			},
			onRestore: function(windowEl){
				MUI.notification('Window was restored.');
			},
			onResize: function(windowEl){
				MUI.notification('Window was resized.');
			},
			onFocus: function(windowEl){
				MUI.notification('Window was focused.');
			},
			onBlur: function(windowEl){
				MUI.notification('Window lost focus.');
			}
		});
	}	
	if ($('windoweventsLinkCheck')){
		$('windoweventsLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MUI.eventsWindow();
		});
	}
	
	MUI.containertestWindow = function(){ 
		new MUI.Window({
			id: 'containertest',
			title: 'Container Test',
			contentURL: 'pages/lipsum.html',
			container: 'pageWrapper',
			width: 340,
			height: 150,
			x: 100,
			y: 100
		});
	}
	if ($('containertestLinkCheck')) { 
		$('containertestLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MUI.containertestWindow();
		});
	}
	
	MUI.iframetestsWindow = function() {
		new MUI.Window({
			id: 'iframetests',
			title: 'Iframe Tests',
			loadMethod: 'iframe',
			contentURL: 'pages/iframetests.html'
		});
	}
	if ($('iframetestsLinkCheck')) {
		$('iframetestsLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MUI.iframetestsWindow();
		});
	}
	
	MUI.formtestsWindow = function() {
		new MUI.Window({
			id: 'formtests',
			title: 'Form Tests',			
			contentURL: 'pages/formtests.html',
			onContentLoaded: function(){
				document.testForm.focusTest.focus();
			}			
		});
	}
	if ($('formtestsLinkCheck')) {
		$('formtestsLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MUI.formtestsWindow();
		});
	}	

	MUI.accordiantestWindow = function() {
		var id = 'accordiantest';
		new MUI.Window({
			id: id,
			title: 'Accordian',			
			contentURL: 'pages/accordian-demo.html',
			width: 300,
			height: 200,
			scrollbars: false,
			resizable: false,
			maximizable: false,				
			padding: { top: 0, right: 0, bottom: 0, left: 0 },
			require: {
				css: [MUI.path.plugins + 'accordian/css/style.css'],
				onload: function(){
					this.windowEl = $(id);				
					new Accordion('#' + id + ' h3.accordianToggler', "#" + id + ' div.accordianElement',{
						opacity: false,
						alwaysHide: true,
						onActive: function(toggler, element){
							toggler.addClass('open');
						},
						onBackground: function(toggler, element){
							toggler.removeClass('open');
						},							
						onStart: function(toggler, element){
							this.windowEl.accordianResize = function(){
								MUI.dynamicResize($(id));
							}
							this.windowEl.accordianTimer = this.windowEl.accordianResize.periodical(10);
						}.bind(this),
						onComplete: function(){
							this.windowEl.accordianTimer = $clear(this.windowEl.accordianTimer);
							MUI.dynamicResize($(id)) // once more for good measure
						}.bind(this)
					}, $(id));
				}	
			}					
		});
	}	
	if ($('accordiantestLinkCheck')) { 
		$('accordiantestLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MUI.accordiantestWindow();
		});
	}

	MUI.noCanvasWindow = function() {
		new MUI.Window({
			id: 'nocanvas',
			title: 'No Canvas',			
			contentURL: 'pages/lipsum.html',
			addClass: 'no-canvas',
			width: 305,
			height: 175,
			shadowBlur: 0,
			resizeLimit: {'x': [275, 2500], 'y': [125, 2000]},
			useCanvas: false
		});
	}
	if ($('noCanvasLinkCheck')) {
		$('noCanvasLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MUI.noCanvasWindow();
		});
	}	

	// View
	if ($('sidebarLinkCheck')) {
		$('sidebarLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MUI.Desktop.sidebarToggle();
		});
	}

	if ($('cascadeLink')) {
		$('cascadeLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.arrangeCascade();
		});
	}

	if ($('tileLink')) {
		$('tileLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.arrangeTile();
		});
	}

	if ($('closeLink')) {
		$('closeLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.closeAll();
		});
	}

	if ($('minimizeLink')) {
		$('minimizeLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.minimizeAll();
		});
	}	

	// Tools
	MUI.builderWindow = function() {	
		new MUI.Window({
			id: 'builder',
			title: 'Window Builder',
			icon: 'images/icons/16x16/page.gif',			
			contentURL: MUI.path.plugins + 'windowform/',
			width: 375,
			height: 420,
			maximizable: false,
			resizable: false,
			scrollbars: false,
			require: {
				css: [MUI.path.plugins + 'windowform/css/style.css'],			
				js: [MUI.path.plugins + 'windowform/scripts/Window-from-form.js'],
				onload: function(){
					$('newWindowSubmit').addEvent('click', function(e){
						new Event(e).stop();
						new MUI.WindowForm();
					});
				}	
			}			
		});
	}
	if ($('builderLinkCheck')) {
		$('builderLinkCheck').addEvent('click', function(e) {
			new Event(e).stop();
			MUI.builderWindow();
		});
	}
	
	if ($('toggleStandardEffectsLinkCheck')) {
		$('toggleStandardEffectsLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MUI.toggleStandardEffects($('toggleStandardEffectsLinkCheck'));			
		});
		if (MUI.options.standardEffects == true) {
			MUI.toggleStandardEffectsLink = new Element('div', {
				'class': 'check',
				'id': 'toggleStandardEffects_check'
			}).inject($('toggleStandardEffectsLinkCheck'));
		}
	}	
	
	if ($('toggleAdvancedEffectsLinkCheck')) {
		$('toggleAdvancedEffectsLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MUI.toggleAdvancedEffects($('toggleAdvancedEffectsLinkCheck'));			
		});
		if (MUI.options.advancedEffects == true) {
			MUI.toggleAdvancedEffectsLink = new Element('div', {
				'class': 'check',
				'id': 'toggleAdvancedEffects_check'
			}).inject($('toggleAdvancedEffectsLinkCheck'));
		}
	}	
		
	// Workspaces
	
	if ($('saveWorkspaceLink')) {
		$('saveWorkspaceLink').addEvent('click', function(e) {
			new Event(e).stop();
			MUI.saveWorkspace();
		});
	}

	if ($('loadWorkspaceLink')) {
		$('loadWorkspaceLink').addEvent('click', function(e) {
			new Event(e).stop();
			MUI.loadWorkspace();
		});
	}
	
	// Help	
	MUI.featuresWindow = function() {
		new MUI.Window({
			id: 'features',
			title: 'Features',			
			contentURL: 'pages/features-layout.html',
			width: 275,
			height: 250,
			resizeLimit: {'x': [275, 2500], 'y': [125, 2000]},
			require: {
				css: [MUI.themePath() + 'css/Tabs.css']
			},			
			toolbar: true,
			toolbarURL: 'pages/features-tabs.html',
			toolbarOnload: function(){
				MUI.initializeTabs('featuresTabs');

				$('featuresLayoutLink').addEvent('click', function(e){
					MUI.updateContent({
						'element':  $('features'),
						'url':       'pages/features-layout.html'
					});
				});

				$('featuresWindowsLink').addEvent('click', function(e){
					MUI.updateContent({
						'element':  $('features'),
						'url':       'pages/features-windows.html'
					});
				});

				$('featuresGeneralLink').addEvent('click', function(e){
					MUI.updateContent({
						'element':  $('features'),
						'url':       'pages/features-general.html'
					});
				});
			}
		});
	}
	if ($('featuresLinkCheck')) {
		$('featuresLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MUI.featuresWindow();
		});
	}

	MUI.aboutWindow = function() {
		new MUI.Modal({
			id: 'about',
			title: 'MUI',			
			contentURL: 'pages/about.html',
			type: 'modal2',
			width: 350,
			height: 195,
			padding: { top: 43, right: 12, bottom: 10, left: 12 },
			scrollbars: false
		});
	}
	if ($('aboutLink')) {
		$('aboutLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.aboutWindow();
		});
	}
	if($('i_hostmanage')){
	//GOTEST
	$('i_hostmanage').addEvent('click', function(e){
		
		MUI.updateContent({
					element: $('mainPanel'),					
					//url: 'index.php?controller=hostmanage&action=list',
					url: 'index.php?controller=hostmanage&action=admins',
					title: '查看主机组',
					padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});


		MUI.updateContent({
					element: $('files-panel'),					
					url: 'index.php?controller=hostmanage&action=quick',
					title: '控制面板'
		});
	});
	}
	
	if($('i_default')){
	$('i_default').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?action=toptenlog',
			title: '最新报警记录',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				//oTimer=setInterval("jQuery.show()",60000);
				window.clearInterval(oTimer);
				oTimer=setInterval("af_toptenlog()",10000);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?action=userwel',
			title: '快速启动',
			onContentLoaded: function(){
				
			}
		});
	});}
	
	if($('m_toptenlog')){
	$('m_toptenlog').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?action=toptenlog',
			title: '最新报警记录',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
				oTimer=setInterval("af_toptenlog()",10000);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?action=userwel',
			title: '快速启动'
		});
	});}

	if($('m_license')){
	$('m_license').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?action=license',
			title: '授权信息',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?action=userwel',
			title: '快速启动'
		});
	});}

	if($('m_mailsetting')){
	$('m_mailsetting').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?action=mailsetting',
			title: '报警邮箱设置',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?action=userwel',
			title: '快速启动'
		});
	});}

	if($('m_remailing')){
	$('m_remailing').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?action=remailing',
			title: '接收邮箱设置',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?action=userwel',
			title: '快速启动'
		});
	});}

	if($('m_serverlog')){
	$('m_serverlog').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?action=serverlog',
			title: '状态日志',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?action=userwel',
			title: '快速启动'
		});
	});}

	if($('m_systeminfo')){
	$('m_systeminfo').addEvent('click', function(e){
		MUI.updateContent({
					element: $('mainPanel'),					
					url: 'index.php?action=systeminfo',
					title: '连接状态',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?action=userwel',
			title: '快速启动',
			onContentLoaded: function(){
				
//				jQuery('#Form_OpSearch').ajaxForm({
//					target: '#mainPanel_pad',
//					success: function(a) {
//						var ati=jQuery('#mainPanel_pad #getting-started').attr('alt');
//						//alert(ati);
//						if(ati)
//							jQuery('#mainPanel_title').html(ati);
//						//jQuery('#tip').html('2009');
//					}
//				});
			}
		});
	});}

	//
	if($('m_admin')){
	$('m_admin').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=hostmanage&action=admin',
			title: '添加组管理员',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?controller=hostmanage&action=quick',
			title: '控制面板'
		});
	});}

	if($('m_blank')){
	$('m_blank').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=hostmanage&action=blank',
			title: '未分组主机',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?controller=hostmanage&action=quick',
			title: '查看主机组'
		});
	});}

	if($('m_admins')){
	$('m_admins').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=hostmanage&action=admins',
			title: '查看主机组',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?controller=hostmanage&action=quick',
			title: '控制面板'
		});
	});}
	
	//addhost_b
	if($('m_addform')){
	$('m_addform').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=hostmanage&action=addform',
			title: '添加主机组',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?controller=hostmanage&action=quick',
			title: '控制面板'
		});
	});}
//	$('hostimport').addEvent('click', function(e){
//		MUI.updateContent({
//					element: $('files-panel'),					
//					url: 'index.php?controller=hostmanage&action=importform',
//					title: '导入主机',
//					onContentLoaded: function(){
//						new AjaxUpload('#button3', {
//							//action: 'upload.php',
//							action: 'index.php?controller=hostmanage&action=upload', // I disabled uploads in this example for security reaaons
//							name: 'userfile',
//							onComplete : function(file){
//								//alert(file);
//								jQuery('<li></li>').appendTo(jQuery('#example3 .files')).text(file);
//							}	
//						});
//					}
//				});
//		
//		//alert('23');
//	});
	
	if($('i_users')){
	$('i_users').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?namespace=admin&controller=users&action=indexpart',
			title: '用户管理',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			//url: 'index.php?action=indexpart',
			url: 'index.php?namespace=admin&controller=users&action=add',
			title: '添加用户'
		});
	});}
	
	if($('i_behaviorlog')){
	$('i_behaviorlog').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			//url: 'index.php?controller=behaviorlog',
			url: 'index.php?controller=behaviorlog&action=list',
			title: '行为日志 > 主机组',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		MUI.updateContent({
			element: $('files-panel'),					
			//url: 'index.php?action=indexpart',
			url: 'index.php?controller=behaviorlog&action=timecheck',
			title: '查询主机',
			onContentLoaded: function(){
//				jQuery("#xia").datecontrol({format:"yyyy-mm-dd"});
//
//				jQuery('#Form_BeSearch').ajaxForm({
//					target: '#mainPanel_pad',
//					success: function(a) {
//						//jQuery('#tip').html('2009');
//					}
//				});
			}
		});
	});}

	if($('i_systemlog')){
	$('i_systemlog').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=systemlog&action=list',
			title: '系统日志 > 主机组',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		
		MUI.updateContent({
			element: $('files-panel'),					
			//url: 'index.php?action=indexpart',
			url: 'index.php?controller=systemlog&action=timecheck',
			title: '查询主机',
			onContentLoaded: function(){
				//document.testForm.focusTest.focus();
				jQuery("#xia").datecontrol({format:"yyyy-mm-dd"});

				jQuery('#Form_BeSearch').ajaxForm({
					target: '#mainPanel_pad',
					success: function(a) {
						//jQuery('#tip').html('2009');
					}
				});
			}
		});
	});}
	//systemlog
	//rulesetting operatelog
	if($('m_rules')){
	$('m_rules').addEvent('click', function(e){
		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?controller=rulesetting&action=ruleaddform',
			title: '添加规则'
		});
		
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=rulesetting&action=rules',
			title: '组规则',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});
	});}

	if($('m_indexguolv')){
	$('m_indexguolv').addEvent('click', function(e){
		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?controller=rulesetting&action=rulegladdform',
			title: '添加规则'
		});
		
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=rulesetting&action=indexguolv',
			title: '过滤规则',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
				jQuery("select[name=ruleselect]").val('1');
			}
		});
	});}

	if($('m_indexbaojing')){
	$('m_indexbaojing').addEvent('click', function(e){
		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?controller=rulesetting&action=rulebjaddform',
			title: '添加规则'
		});
		
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=rulesetting&action=indexbaojing',
			title: '报警规则',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
				jQuery("select[name=ruleselect]").val('0');
			}
		});
	});}

	if($('i_rulesetting')){
	$('i_rulesetting').addEvent('click', function(e){
		
		MUI.updateContent({
			element: $('files-panel'),					
			url: 'index.php?controller=rulesetting&action=ruleaddform',
			title: '添加规则',
			onContentLoaded: function(){
		
		

			}
		});
		
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=rulesetting',
			title: '规则设置',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});
	});}

	if($('i_operatereport')){
	$('i_operatereport').addEvent('click', function(e){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=operatereport',
			title: '操作报告',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});

		//
		MUI.updateContent({
			element: $('files-panel'),					
			//url: 'index.php?action=indexpart',
			url: 'index.php?controller=operatereport&action=output',
			title: '查询报告',
			onContentLoaded: function(){
				//document.testForm.focusTest.focus();
				jQuery("#xia").datecontrol({format:"yyyy-mm-dd"});

				jQuery('#Form_OpSearch').ajaxForm({
					target: '#mainPanel_pad',
					success: function(a) {
						var ati=jQuery('#mainPanel_pad #getting-started').attr('alt');
						//alert(ati);
						if(ati)
							jQuery('#mainPanel_title').html(ati);
						//jQuery('#tip').html('2009');
					}
				});
			}
		});
	});}
	// Misc
	MUI.licenseWindow = function() {
		new MUI.Window({
			id: 'License',
			title: 'License',						
			contentURL: 'license.html',
			width: 375,
			height: 340
		});
	}	
	if ($('licenseLink')){ 
		$('licenseLink').addEvent('click', function(e) {
			new Event(e).stop();
			MUI.licenseWindow();
		});
	}	

	// Deactivate menu header links
	$$('a.returnFalse').each(function(el) {
		el.addEvent('click', function(e) {
			new Event(e).stop();
		});
	});
	
	// Build windows onLoad
	//MUI.parametricsWindow();

	MUI.myChain.callChain();
	
}

/*
  
INITIALIZE COLUMNS AND PANELS  

	Creating a Column and Panel Layout:
	 
	 - If you are not using panels then these columns are not required.
	 - If you do use panels, the main column is required. The side columns are optional.
	 
	 Columns
	 - Create your columns from left to right.
	 - One column should not have it's width set. This column will have a fluid width.
	 
	 Panels
	 - After creating Columns, create your panels from top to bottom, left to right.
	 - One panel in each column should not have it's height set. This panel will have a fluid height.	 
	 - New Panels are inserted at the bottom of their column. 
 
-------------------------------------------------------------------- */


initializeColumns = function() {

	new MUI.Column({
		id: 'sideColumn1',
		placement: 'left',
		width: 200,
		resizeLimit: [100, 300]
	});
	
	new MUI.Column({
		id: 'mainColumn',
		placement: 'main',
		resizeLimit: [100, 300]
	});
	
//	new MUI.Column({
//		id: 'sideColumn2',
//		placement: 'right',
//		width: 220,
//		resizeLimit: [200, 300]
//	});
	
	// Add panels to first side column
	new MUI.Panel({
		id: 'files-panel',
		title: '快速启动',		
		contentURL: 'index.php?action=userwel',
		column: 'sideColumn1',
		collapsible: false,
		onContentLoaded: function(){
			//jQuery('.userwel_box').html();
			//jQuery('#iul_default').clone(true).appendTo('.userwel_box');
		}	
	});
	
	new MUI.Panel({
		id: 'mainPanel',
		title: '最新报警记录',
		contentURL: 'index.php?action=toptenlog',
		column: 'mainColumn',
		headerToolbox: false,
		collapsible: false,
		onContentLoaded: function(){
			window.clearInterval(oTimer);
			oTimer=setInterval("af_toptenlog()",10000);	
		}
	});
	
	MUI.splitPanelPanel = function() {
		if ($('mainPanel')) {			
			new MUI.Column({
				container: 'mainPanel',
				id: 'sideColumn3',
				placement: 'left',
				width: 200,
				resizeLimit: [100, 300]
			});
			
			new MUI.Column({
				container: 'mainPanel',
				id: 'mainColumn2',
				placement: 'main',
				width: null,
				resizeLimit: [100, 300]
			});
			
			new MUI.Panel({
				header: false,
				id: 'splitPanel_mainPanel',
				contentURL: 'license.html',
				column: 'mainColumn2'
			});
			
			new MUI.Panel({
				header: false,
				id: 'splitPanel_sidePanel',
				addClass: 'panelAlt',
				contentURL: 'pages/lipsum.html',
				column: 'sideColumn3'
			});
		}
	}
	
	MUI.myChain.callChain();
	
}

// Initialize MochaUI when the DOM is ready
window.addEvent('load', function(){ //using load instead of domready for IE8

	MUI.myChain = new Chain();
	MUI.myChain.chain(
		function(){MUI.Desktop.initialize();},
		function(){MUI.Dock.initialize();},
		function(){initializeColumns();},		
		function(){initializeWindows();}		
	).callChain();	

});

//ajax翻页
function opgopage(a){
	//alert('fdffd');
	
	var keys = a.split('|');
	var macstr='';

	if(isNaN(keys[2]))
			return false;
	
	//alert(jQuery('#startd').val());
	if(keys[2]==-1 && jQuery('#gotopage').val()!=''){
		keys[2]=jQuery('#gotopage').val();
		if(isNaN(keys[2]))
			return false;

		var maxp=jQuery('#gotopage').attr('title');
		if(parseInt(keys[2])<1 || keys[2]=='')keys[2]=1;
		//alert(maxp);
		if(parseInt(keys[2])>parseInt(maxp)){keys[2]=maxp;}
	}else if(keys[2]==-1 && jQuery('#gotopage').val()==''){
		return false;
	}
	if(jQuery("#macs").val())
		macstr='&mac='+jQuery("#macs").val();

	if(jQuery("#ids").val())
		macstr='&id='+jQuery("#ids").val();

	if(jQuery("#groupids").val())
		macstr='&groupid='+jQuery("#groupids").val();

	if(jQuery("#logstr").val())
		macstr+='&logstr='+jQuery("#logstr").val();

	if(jQuery("#ipstr").val())
		macstr+='&ipstr='+jQuery("#ipstr").val();

	if(jQuery("#namestr").val())
		macstr+='&namestr='+jQuery("#namestr").val();

	if(jQuery("#perpage").val())
		macstr+='&per='+jQuery("#perpage").val();

	//alert(macstr);

	if(keys[2]!=''){
	//alert(keys[0]);
		if(jQuery('#startd').val()!='' && jQuery('#endd').val()!=''){
		
		jQuery('#mainPanel_pad').load('index.php?controller='+keys[0]+'&action='+keys[1]+'&page='+keys[2]+'&startd='+jQuery('#startd').val()+'&endd='+jQuery('#endd').val()+macstr, function() {
			//alert('Load was performed.');
		});

		}else{
			jQuery('#mainPanel_pad').load('index.php?controller='+keys[0]+'&action='+keys[1]+'&page='+keys[2]+macstr, function() {
				//alert('Load was performed.');
			});
		}
	}
}

function opgopage1(a){
	//alert('21qw');
	
	var keys = a.split('|');
	//alert(jQuery('#startd').val());
	if(keys[3]==-1 && jQuery('#gotopage').val()!=''){
		keys[3]=jQuery('#gotopage').val();
	}

	var macstr='';
	if(jQuery("#macs").val())
		macstr='&mac='+jQuery("#macs").val();

	if(jQuery("#ids").val())
		macstr='&id='+jQuery("#ids").val();

	if(jQuery("#groupids").val())
		macstr='&groupid='+jQuery("#groupids").val();

	if(keys[3]!=''){
	//alert(keys[0]);
		if(jQuery('#startd').val()!='' && jQuery('#endd').val()!=''){
		
		jQuery('#mainPanel_pad').load('index.php?namespace='+keys[0]+'&controller='+keys[1]+'&action='+keys[2]+'&page='+keys[3]+'&startd='+jQuery('#startd').val()+'&endd='+jQuery('#endd').val()+macstr, function() {
			//alert('Load was performed.');
		});
		//http://localhost:9000/hids/public/index.php?namespace=admin&controller=users&action=indexpart
		}else{
			jQuery('#mainPanel_pad').load('index.php?namespace='+keys[0]+'&controller='+keys[1]+'&action='+keys[2]+'&page='+keys[3]+macstr, function() {
				//alert('Load was performed.');
			});
		}
	}
}

function goexcel(){
	//alert('qwqw');
	var varse1 = new Object();
	varse1['startdate'] = jQuery("input[name=startdate]").val();
	varse1['enddate'] = jQuery("input[name=enddate]").val();
	varse1['excel'] = '1';
	jQuery("#mainPanel_pad").load("index.php?controller=operatereport",varse1,function(){
		//alert('asa');
		//jQuery('#tip').html('<a href="output.xls" target="_blank">下载</a>');
		//window.open('output.xls');
		//alert(jQuery.browser.version);
		if(jQuery.browser.msie){
			jQuery("#down1").attr('src','output.xls');
		}else
			window.open('output.xls');
	});
}

function godelete(){
	if(jQuery("input[name=startdate]").val() && jQuery("input[name=enddate]").val()){
	
		if(confirm("确认删除吗？")){
		
			//alert('qwqw');
			var varse1 = new Object();
			varse1['startdate'] = jQuery("input[name=startdate]").val();
			varse1['enddate'] = jQuery("input[name=enddate]").val();
			jQuery("#mainPanel_pad").load("index.php?controller=operatereport&action=delete",varse1,function(){
				//alert('asa');
				freshop();
			});
		}
	}else{
		alert('请先选择时间范围！')
	}
}

function freshhostgroup(){
	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?controller=hostmanage&action=blank',
		title: '未分组主机',
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});
}

function freshgroup(){
	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?controller=hostmanage&action=admins',
		title: '主机组',
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});
}

function freshaddrule(){
	MUI.updateContent({
		element: $('files-panel'),					
		url: 'index.php?controller=rulesetting&action=ruleaddform',
		title: '添加新规则',
		onContentLoaded: function(){
			//window.clearInterval(oTimer);
		}
	});

	MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=rulesetting',
			title: '规则设置',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
	});
}

function freshgaddrule(a,b){
	MUI.updateContent({
		element: $('files-panel'),					
		url: 'index.php?controller=rulesetting&action=ruleaddform',
		title: '添加新规则',
		onContentLoaded: function(){
			//window.clearInterval(oTimer);
			jQuery("select#groupid").val(a);
		}
	});
	var goourl='';
	alert(b);
	if(b!='' && b)
		goourl='index.php?controller=rulesetting&action=index&flag='+b+'&id='+a;
	else
		goourl='index.php?controller=rulesetting&action=indexgroup&id='+a;

	MUI.updateContent({
			element: $('mainPanel'),					
			url: goourl,
			title: '组规则设置',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
	});
}

function freshgaddrule1(a){
	MUI.updateContent({
		element: $('files-panel'),					
		url: 'index.php?controller=rulesetting&action=ruleaddform',
		title: '添加新规则',
		onContentLoaded: function(){
			//window.clearInterval(oTimer);
			jQuery("select#groupid").val(a);
		}
	});

	goourl='index.php?controller=rulesetting&action=index&id='+a;

	MUI.updateContent({
			element: $('mainPanel'),					
			url: goourl,
			title: '组规则设置',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
	});
}

function freshaddgroup(){
	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?controller=hostmanage&action=addform',
		title: '添加主机组',
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});
}

function freshaddgroup_l(){
	MUI.updateContent({
		element: $('files-panel'),					
		url: 'index.php?controller=hostmanage&action=quick',
		title: '控制面板',
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});
}

function freshop(){
	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?controller=operatereport',
		title: '操作报告',
		padding: { top: 8, right: 8, bottom: 8, left: 8 },
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});
}

function allchecked(namestr){
	var to=0;
	var numbers = new Array();
	$$('.check-me').each(function(el) { 
			if(el.checked)
			{
				numbers.push(el.get('value'));
				//alert(el.get('value'));
				to++;
			}
	});
	$(namestr).set('value',numbers);
	//alert($(namestr).get('value'));
}

function modifypwd(){

	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?action=changepasswd',
		title: '修改密码',
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});

}

function allalarmtable(){
	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?action=alarmtable',
		title: '行为日志报警',
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});

}

function alleventalarm(){
	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?action=eventalarm',
		title: '系统日志报警',
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});
}

function reashrules(){
	//jQuery("select[name='ruleselect'] option[selected]").text();
	var lv=jQuery("select[name=ruleselect]").val();
	var lg='';
	lg=jQuery("select[name=ruleselect]").attr('title');
	if(lg){
		if(lg!='')
			lg='&id='+lg;
	}

	if(lv==''){
		//alert('asas');
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?controller=rulesetting'+lg+'',
			title: '全部规则',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
		onContentLoaded: function(){
			window.clearInterval(oTimer);
			jQuery("select[name=ruleselect]").val('');
		}
		});
	}else{
		
		if(lv==1){
			MUI.updateContent({
				element: $('mainPanel'),					
				url: 'index.php?controller=rulesetting'+lg+'&action=indexguolv',
				title: '过滤规则',
				padding: { top: 8, right: 8, bottom: 8, left: 8 },
		onContentLoaded: function(){
			window.clearInterval(oTimer);
			jQuery("select[name=ruleselect]").val('1');
		}
			});
		}else if(lv==0){
			MUI.updateContent({
				element: $('mainPanel'),					
				url: 'index.php?controller=rulesetting'+lg+'&action=indexbaojing',
				title: '报警规则',
				padding: { top: 8, right: 8, bottom: 8, left: 8 },
		onContentLoaded: function(){
			window.clearInterval(oTimer);
			jQuery("select[name=ruleselect]").val('0');
		}
			});
		}

	}
}

function freshmailset(){
		MUI.updateContent({
			element: $('mainPanel'),					
			url: 'index.php?action=mailsetting',
			title: '报警邮箱设置',
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
		});
}

function af_toptenlog(){
	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?action=toptenlog',
		title: '最新报警记录',
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});
}

function navgo1(){
	MUI.updateContent({
			element: $('mainPanel'),
			url: 'index.php?controller=behaviorlog&action=list',
			title: '行为日志 > 主机组',
			padding: { top: 8, right: 8, bottom: 8, left: 8 },
			onContentLoaded: function(){
				window.clearInterval(oTimer);
			}
	});

	MUI.updateContent({
		element: $('files-panel'),
		url: 'index.php?controller=behaviorlog&action=timecheck',
		title: '查询主机'
	});
}

function navgo2(){
	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?controller=systemlog&action=list',
		title: '系统日志 > 主机组',
		padding: { top: 8, right: 8, bottom: 8, left: 8 },
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});

		
	MUI.updateContent({
		element: $('files-panel'),
		url: 'index.php?controller=systemlog&action=timecheck',
		title: '查询主机'
	});
}

function navgo3(){
	MUI.updateContent({
		element: $('mainPanel'),					
		url: 'index.php?controller=hostmanage&action=admins',
		title: '查看主机组',
		padding: { top: 8, right: 8, bottom: 8, left: 8 },
		onContentLoaded: function(){
			window.clearInterval(oTimer);
		}
	});

		
	MUI.updateContent({
		element: $('files-panel'),
		url: 'index.php?controller=hostmanage&action=quick',
		title: '控制面板'
	});
}
